<template>
  <view class="page">
    <!-- 状态栏占位 -->
    <view :style="{ height: statusBarHeight + 'px' }"></view>

    <!-- 导航栏 -->
    <view class="nav-bar">
      <view class="nav-left" @tap="goBack">
        <text class="icon fa fa-arrow-left fa-gray"></text>
      </view>
      <view class="nav-title">错题本</view>
      <view class="nav-right" @tap="handleExport">
        <text class="export-text">导出</text>
      </view>
    </view>

    <!-- 主内容 -->
    <scroll-view scroll-y class="content">
      <!-- 筛选标签 -->
      <view class="filter-tabs">
        <view
          v-for="(filter, index) in filters"
          :key="index"
          class="filter-tab"
          :class="{ 'filter-tab-active': currentFilter === index }"
          @tap="selectFilter(index)"
        >
          <text
            class="filter-tab-text"
            :class="{ 'filter-tab-text-active': currentFilter === index }"
          >
            {{ filter }}
          </text>
        </view>
      </view>

      <!-- 错题列表 -->
      <view class="mistakes-list">
        <!-- 错题1 -->
        <view class="mistake-card">
          <text class="mistake-source">内科住培 · 阶段考试</text>
          <text class="mistake-question"
            >以下哪项不属于脓毒症的主要临床表现？</text
          >
          <view class="mistake-answers">
            <text class="mistake-answer-wrong">你的答案：D</text>
            <text class="mistake-answer-correct">正确答案：C</text>
          </view>
          <view class="mistake-explanation">
            <text class="explanation-text"
              >解析：脓毒症常见呼吸急促（频率升高），降低并不典型。</text
            >
          </view>
          <view class="mistake-actions">
            <view
              class="action-btn action-btn-review"
              @tap="handleAddReview(0)"
            >
              <text class="action-btn-text">加入复习</text>
            </view>
            <view class="action-btn action-btn-remove" @tap="handleRemove(0)">
              <text class="action-btn-text">移除</text>
            </view>
          </view>
        </view>

        <!-- 错题2 -->
        <view class="mistake-card">
          <text class="mistake-source">CTA临床思维测评</text>
          <text class="mistake-question"
            >ARDS 的诊断标准包含哪些？（多选）</text
          >
          <view class="mistake-answers">
            <text class="mistake-answer-wrong">你的答案：A/C</text>
            <text class="mistake-answer-correct">正确答案：A/B/D</text>
          </view>
          <view class="mistake-explanation">
            <text class="explanation-text"
              >解析：根据柏林定义，需结合氧合指数、影像、时间窗等。</text
            >
          </view>
          <view class="mistake-actions">
            <view
              class="action-btn action-btn-review"
              @tap="handleAddReview(1)"
            >
              <text class="action-btn-text">加入复习</text>
            </view>
            <view class="action-btn action-btn-remove" @tap="handleRemove(1)">
              <text class="action-btn-text">移除</text>
            </view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      statusBarHeight: 0,
      filters: ["全部", "单选题", "多选题", "案例题"],
      currentFilter: 0,
    };
  },
  onLoad() {
    // 获取系统状态栏高度
    const systemInfo = uni.getSystemInfoSync();
    this.statusBarHeight = systemInfo.statusBarHeight || 0;
  },
  methods: {
    // 返回上一页
    goBack() {
      uni.navigateBack();
    },

    // 导出错题
    handleExport() {
      uni.showToast({
        title: "导出功能开发中",
        icon: "none",
      });
    },

    // 选择筛选项
    selectFilter(index) {
      this.currentFilter = index;
      uni.showToast({
        title: `筛选：${this.filters[index]}`,
        icon: "none",
      });
    },

    // 加入复习
    handleAddReview(index) {
      uni.showToast({
        title: "已加入复习计划",
        icon: "success",
      });
    },

    // 移除错题
    handleRemove(index) {
      uni.showModal({
        title: "确认移除",
        content: "确定要从错题本中移除这道题吗？",
        success: (res) => {
          if (res.confirm) {
            uni.showToast({
              title: "已移除",
              icon: "success",
            });
          }
        },
      });
    },
  },
};
</script>

<style scoped>
.page {
  min-height: 100vh;
  background-color: #ffffff;
  display: flex;
  flex-direction: column;
}

/* 导航栏 */
.nav-bar {
  height: 44px;
  background-color: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.nav-left {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.icon-back {
  font-size: 24px;
  color: #4b5563;
}

.nav-title {
  font-size: 17px;
  font-weight: 600;
  color: #000000;
}

.nav-right {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.export-text {
  font-size: 14px;
  color: #6b7280;
}

/* 主内容 */
.content {
  flex: 1;
  padding: 0 16px;
  box-sizing: border-box;
}

/* 筛选标签 */
.filter-tabs {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  overflow-x: auto;
}

.filter-tab {
  padding: 6px 12px;
  border-radius: 999px;
  background-color: #f3f4f6;
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-tab-active {
  background-color: #2563eb;
}

.filter-tab-text {
  font-size: 14px;
  color: #374151;
}

.filter-tab-text-active {
  color: #ffffff;
}

/* 错题列表 */
.mistakes-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}

.mistake-card {
  background-color: #f9fafb;
  border-radius: 16px;
  padding: 16px;
}

.mistake-source {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.mistake-question {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: #111827;
  margin-bottom: 8px;
  line-height: 1.5;
}

/* 答案区域 */
.mistake-answers {
  margin-bottom: 8px;
}

.mistake-answer-wrong {
  display: block;
  font-size: 12px;
  color: #f43f5e;
  margin-bottom: 2px;
}

.mistake-answer-correct {
  display: block;
  font-size: 12px;
  color: #059669;
}

/* 解析区域 */
.mistake-explanation {
  background-color: #ffffff;
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
}

.explanation-text {
  font-size: 12px;
  color: #4b5563;
  line-height: 1.6;
}

/* 操作按钮 */
.mistake-actions {
  display: flex;
  gap: 8px;
}

.action-btn {
  flex: 1;
  padding: 6px 12px;
  border-radius: 8px;
  text-align: center;
}

.action-btn-review {
  background-color: #f3f4f6;
}

.action-btn-remove {
  background-color: #f3f4f6;
}

.action-btn-text {
  font-size: 12px;
  color: #374151;
}
</style>
